﻿<UserControl x:Class="FieldTest.FieldTestControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0"
             xmlns:Model="clr-namespace:FieldTest.Core.Model;assembly=FieldTest.Core"
             xmlns:Local="clr-namespace:FieldTest"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="300"
             Name="FieldTestWindow" MouseDoubleClick="FieldTestWindow_MouseDoubleClick">
    <UserControl.Resources>
        <Local:TestStatusConverter x:Key="TestStatusConverter" />
        <Local:TestProgressIconVisibilityConverter x:Key="TestProgressIconVisibilityConverter" />
        <Local:GlobalProgressIconVisibilityConverter x:Key="GlobalProgressIconVisibilityConverter" />
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="32"/>
            <RowDefinition Height="0"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <StackPanel Orientation="Horizontal">
                <Button Name="RunAllTestsButton" Margin="10, 3, 0, 3" Width="20" Height="20" Click="RunAllTests_Click" IsEnabled="{Binding Path=CanRunTests}">
                    <Image Source="/FieldTest;component/Resources/RunAll.png" ToolTip="Run all tests in solution" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"></Image>
                </Button>
                <Button Name="RunSelectedTestsButton" Margin="10, 3, 0, 3" Width="20" Height="20" Click="RunSelectedTests_Click" IsEnabled="{Binding Path=CanRunTests}">
                    <Image Source="/FieldTest;component/Resources/Run.png" ToolTip="Run selected tests" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"></Image>
                </Button>
                <Button Name="DebugSelectedTests" Margin="10, 3, 0, 3" Width="20" Height="20" Click="DebugSelectedTests_Click" IsEnabled="{Binding Path=CanRunTests}">
                    <Image Source="/FieldTest;component/Resources/RunDebug.png" ToolTip="Run selected tests in debug mode" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"></Image>
                </Button>
                <Button Name="DebugAllTests" Margin="10, 3, 0, 3" Width="20" Height="20" Click="DebugAllTests_Click" IsEnabled="{Binding Path=CanRunTests}">
                    <Image Source="/FieldTest;component/Resources/RunDebugAll.png" ToolTip="Run all tests in debug mode" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"></Image>
                </Button>
            </StackPanel>

            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10, 3, 10, 3" HorizontalAlignment="Right">
                <Local:ProgressIcon Visibility="{Binding Path=TestsAreRunning, Converter={StaticResource ResourceKey=GlobalProgressIconVisibilityConverter}}"></Local:ProgressIcon>
                <Label Name="Progress"></Label>
            </StackPanel>
        </Grid>

        <StackPanel Orientation="Horizontal" Margin="10" Grid.Row="1">
            <Button>ICON</Button>
            <TextBlock Margin="10" HorizontalAlignment="Left" Background="{x:Null}">This is a toolwindow with WPF content</TextBlock>
        </StackPanel>
        
        <Grid Grid.Row="2">
            <TreeView Name="TestsInSolution" ItemsSource="{Binding Path=TestAssemblies}" SelectedItemChanged="TestsInSolution_SelectedItemChanged">
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <!-- Style for the selected item -->
                        <Setter Property="BorderThickness" Value="1"/>
                        <Setter Property="IsExpanded" Value="True"></Setter>
                        <Style.Triggers>
                            <!-- Selected and has focus -->
                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                <Setter Property="BorderBrush" Value="#7DA2CE"/>
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <GradientStop Color="#FFDCEBFC" Offset="0"/>
                                            <GradientStop Color="#FFC1DBFC" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                            
                            <!-- Selected but does not have the focus -->
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding IsSelected}" Value="True"/>
                                    <Condition Binding="{Binding IsSelectionActive}" Value="False"/>
                                    
                                    <!--<Condition Property="IsSelected" Value="True"/>
                                    <Condition Property="IsSelectionActive" Value="False"/>-->
                                </MultiDataTrigger.Conditions>
                                <Setter Property="BorderBrush" Value="#D9D9D9"/>
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <GradientStop Color="#FFF8F8F8" Offset="0"/>
                                            <GradientStop Color="#FFE5E5E5" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </MultiDataTrigger>
                        </Style.Triggers>
                        <Style.Resources>
                            <Style TargetType="Border">
                                <Setter Property="CornerRadius" Value="2"/>
                            </Style>
                        </Style.Resources>
                    </Style>
                </TreeView.ItemContainerStyle>
                
                <TreeView.Resources>
                    <!-- Brushes for the selected item -->
                    <!--<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"></SolidColorBrush>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"></SolidColorBrush>-->
                    <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFDCEBFC" Offset="0"/>
                        <GradientStop Color="#FFC1DBFC" Offset="1"/>
                    </LinearGradientBrush>
                    <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}" EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFF8F8F8" Offset="0"/>
                        <GradientStop Color="#FFE5E5E5" Offset="1"/>
                    </LinearGradientBrush>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
                </TreeView.Resources>
                
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type Model:TestAssembly}" ItemsSource="{Binding Path=TestClasses}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=AssemblyName}"></TextBlock>
                        </StackPanel>
                        
                        <HierarchicalDataTemplate.ItemTemplate>
                            <HierarchicalDataTemplate DataType="{x:Type Model:TestClass}" ItemsSource="{Binding Path=Tests}">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=ClassName}"></TextBlock>
                                </StackPanel>
                                
                                <HierarchicalDataTemplate.ItemTemplate>
                                    <HierarchicalDataTemplate DataType="{x:Type Model:TestDetails}">
                                        <StackPanel Orientation="Horizontal" Tag="{Binding}" ToolTip="{Binding Path=Message}">
                                            <Image Stretch="None" Source="{Binding Path=Status, Converter={StaticResource ResourceKey=TestStatusConverter}}" ToolTip="{Binding Path=Message}"></Image>
                                            <Local:ProgressIcon Visibility="{Binding Path=Status, Converter={StaticResource ResourceKey=TestProgressIconVisibilityConverter}}"></Local:ProgressIcon>
                                            <TextBlock Text="{Binding Path=MethodName}" ToolTip="{Binding Path=Message}"></TextBlock>
                                        </StackPanel>
                                    </HierarchicalDataTemplate>
                                </HierarchicalDataTemplate.ItemTemplate>
                            </HierarchicalDataTemplate>
                        </HierarchicalDataTemplate.ItemTemplate>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
        </Grid>
    </Grid>
</UserControl>